package com.xiaoxiao.springbootstudy.mapper;

import com.xiaoxiao.springbootstudy.pojo.AfterScale;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xiaoxiao.springbootstudy.pojo.vo.CountResult;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
* @author XiaoXiao
* @description 针对表【t_after_scales】的数据库操作Mapper
* @createDate 2025-05-13 14:45:56
* @Entity com.xiaoxiao.springbootstudy.pojo.AfterScale
*/
public interface AfterScaleMapper extends BaseMapper<AfterScale> {

    @Select({"<script>",
            "SELECT aft.*, cust.cust_name custName from t_customer cust INNER JOIN t_after_sales aft ON cust.id = aft.cust_id",
                "<where>",
                    "<if test=\"id!=null\">",
                        "aft.id = #{id}",
                    "</if>",
                    "<if test=\"question !=null and question != ''\">",
                        "question==#{question}",
                    "</if>",
                    "<if test=\"state != null and state != ''\">",
                        "and state = #{state}",
                    "</if>",
                    "<if test=\"grade != null and grade != ''\">",
                        "and grade = #{grade}",
                    "</if>",
                "</where>",
            "</script>"})
    List<AfterScale> queryAfterSaleListMapper(AfterScale scale);

    @Select("SELECT question name, COUNT(id) value FROM `t_after_sales` GROUP BY question")
    List<CountResult> countQuestionTypeMapper();

    @Select("SELECT  state name, COUNT(id) value FROM `t_after_sales` GROUP BY state")
    List<CountResult> countStateMapper();
}




